package com.leetcode.LC;

public class LC1013 {
    public boolean canThreePartsEqualSum(int[] arr) {
        int sum = 0;
        for (int i : arr) {
            sum += i;
        }
        if (sum % 3 != 0) {
            return false;
        }

        sum /= 3;
        int a = 0, b = 0;
        for (int i = 0; i < arr.length; i++) {
            a += arr[i];
            if (a == sum) {
                b++;
                if (b == 2) {
                    if (i == arr.length - 1) {
                        return false;
                    } else {
                        return true;
                    }
                }
                a = 0;
            }
        }
        return false;

    }

    public static void main(String[] args) {
        System.out.println(new LC1013().canThreePartsEqualSum(new int[]{1, -1, 1, -1}));
    }
}
